import config from "@/config/config.js";
import http from "@/api/http.js";


const shipmentRequest = {
    loadShipment(shipment,page=1,limit=10,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.defectBaseUrl + "/shipment/list?page="+page + "&limit="+limit;
            if(shipment){
                if (shipment.shipmentId){
                    url += "&shipmentId=" + shipment.shipmentId;
                }
                if(shipment.shipmentName){
                    url += "&shipmentName=" + shipment.shipmentName;
                }
            }
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },
    saveShipment(shipment,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/shipment/save";
            http.post(url,shipment,callBack);
        }else {
            callBack(undefined);
        }
    },
    updateShipmentById(shipment,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/shipment/update";
            http.put(url,shipment,callBack);
        } else {
            callBack(undefined);
        }
    },
    selectById(shipmentId,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/shipment/get?shipmentId=" + shipmentId;
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },
    export(shipment,page=1,limit=10,callBack){
        let token = localStorage.getItem("token");
        if (token){
            let url = config.defectBaseUrl + "/shipment/export?page=" + page + "&limit=" + limit;
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },







}

export default shipmentRequest